package main

import (
	"fmt"
	"net/http"
	"os"
	"os/signal"
	"syscall"
	"user_manager/routers"

	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
)

func main () {

    // 初始化配置

    // 创建 gin 服务
    server := gin.New()
    routers.InitRouter(server)

    logrus.Info("start http gin");

    // 启动服务
    srv := &http.Server{
        Addr:    fmt.Sprintf("%s:%d", "0.0.0.0", 9025),
        Handler: server,
    }

    defer func() {
        if err := srv.Close(); err != nil {
            logrus.Fatal("Server Shutdown:", err)
        }
    }()

    go func() {
        if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
            logrus.Fatalf("listen: %s\n", err)
        }
    }()

    logrus.Info("The Server has started.")

    quit := make(chan os.Signal)
    signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
    <-quit
    logrus.Info("Shutting down server...")
}